package com.ms.oschina.ui.activity;

import uk.co.senab.photoview.PhotoViewAttacher;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.ms.oschina.R;
import com.ms.oschina.base.BaseActivity;
import com.ms.oschina.bean.Constants;
import com.ms.oschina.util.UiUtils;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;

public class ImagePreActivity extends BaseActivity {
	private ProgressBar pb;
	private ImageView ivSmall;
	private ImageView ivBig;

	private void findViews() {
		pb = (ProgressBar) findViewById(R.id.pb_imgpre);
		ivSmall = (ImageView) findViewById(R.id.iv_imgpre_small);
		ivBig = (ImageView) findViewById(R.id.iv_imgpre_big);
	}
	
	

	@Override
	protected int getLayoutId() {
		return R.layout.activity_imgpre;
	}

	@Override
	protected void initView() {
		findViews();
	}

	@Override
	protected void initData() {
		Intent intent = getIntent();
		String smallImageUrl = intent.getStringExtra(Constants.SMALL_IMAGE_URL);
		final String bigImageUrl = intent
				.getStringExtra(Constants.BIG_IMAGE_URL);
		
		if (!TextUtils.isEmpty(smallImageUrl)) {
			Picasso.with(UiUtils.getContext()).load(smallImageUrl).into(ivSmall);
		}

		final PhotoViewAttacher mAttacher = new PhotoViewAttacher(ivBig);
		Picasso.with(UiUtils.getContext()).load(bigImageUrl).into(ivBig, new Callback() {

					@Override
					public void onError() {
					}

					@Override
					public void onSuccess() {
						ivSmall.setVisibility(View.GONE);
						pb.setVisibility(View.GONE);
						mAttacher.update();
					}
				});
	}
	
	@Override
	protected boolean isFullScreen() {
		return true;
	}
}
